package com.txl.domain;

import java.util.HashMap;
import java.util.Map;

public class UserForm {

	private String username;//用户名
	private String password;//密码
	private String password2;//确认密码
	private String checkcode;//验证码
	private Map errors = new HashMap();
	
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPassword2() {
		return password2;
	}

	public void setPassword2(String password2) {
		this.password2 = password2;
	}

	public String getCheckcode() {
		return checkcode;
	}

	public void setCheckcode(String checkcode) {
		this.checkcode = checkcode;
	}

	public Map getErrors() {
		return errors;
	}

	public void setErrors(Map errors) {
		this.errors = errors;
	}

	public boolean validate(String s_checkcode){
		boolean isOK = true;
		
		if(username==null || username.trim().equals("")){
			errors.put("username", "用户名不能为空");
			isOK = false;
		}else if(!username.matches("\\w{3,8}")){
			errors.put("username", "用户名3-8位");
			isOK = false;
		}
		
		if(password==null || password.trim().equals("")){
			errors.put("password", "密码不能为空");
			isOK = false;
		}else if(!password.matches("\\d{6,8}")){
			errors.put("password", "密码6-8位");
			isOK = false;
		}
		
		if(checkcode==null || checkcode.trim().equals("")){
			errors.put("checkcode", "验证码不能为空");
			isOK = false;
		}else if(!checkcode.equals(s_checkcode)){
			errors.put("checkcode", "验证码错误");
			isOK = false;
		}
		
		if(password2==null || password2.trim().equals("")){
			errors.put("password2", "密码不能为空");
			isOK = false;
		}else if(!password2.equals(password)){
			errors.put("password2", "两次密码输入不一致");
			isOK = false;
		}

		return isOK;
	}
}

